#pragma once
#include <mysql_driver.h>
#include <mysql_connection.h>
#include <cppconn/driver.h>
#include <cppconn/statement.h>
#include <fstream>
#include <sstream>
#include <string>
#include <stdio.h>
#include <boost/format.hpp>
#include <string>

enum OpState{
    DRIVER_DOWN,
    CONNECTION_DOWN,
    STATEMENT_EROR,
    DRIVER_UP = 0x10,
    CONNECTION_UP,
    STATEMENT_PASS,
};



class DataBaseProperty {
public:
    sql::SQLString      host;
    sql::SQLString      user;
    sql::SQLString      passwd;

    DataBaseProperty() = default;
    DataBaseProperty(const std::string &host, const std::string &user, const std::string &passwd): 
        host(host), user(user), passwd(passwd) {}
    
    DataBaseProperty& operator=(const DataBaseProperty & other) {
        this->host = other.host;
        this->user = other.user;
        this->passwd = other.passwd;
        return *this;
    }
};




class OpMysql {
private:
    sql::Driver         *driver;
    sql::Connection     *conn;
    sql::Statement      *stmt;

public:
    sql::ResultSet      *res;

    DataBaseProperty    *db;

    friend void DisplayOpMysql(const OpMysql &op);


public:
    OpMysql(const std::string &host, const std::string &user, const std::string &passwd);
    ~OpMysql();
    OpState connect();
    OpState connect(const DataBaseProperty &db);
    OpState execute(const std::string &sql);
    sql::ResultSet* executeQueue(const std::string &sql);

};


void test_mysql();
void test2_mysql();
int test_fileIO();
int test_string();